//
//  Hot_rodTableViewCell.m
//  CarOfHome2
//
//  Created by 微 醺 on 15/9/23.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "Hot_rodTableViewCell.h"
#import "Hot_rodModel.h"

@implementation Hot_rodTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.img = [[UIImageView alloc] init];
        [self.contentView addSubview:_img];
        
        self.view = [[UIView alloc] init];
        self.view.backgroundColor = [UIColor lightGrayColor];
        [_img addSubview:_view];
        
        self.picture = [[UIImageView alloc] init];
        self.picture.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"pic"]];
        [_view addSubview:_picture];
        
        self.share = [[UIImageView alloc] init];
        _share.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"fenxiang1"]];
        [_view addSubview:_share];
        
        self.top = [[UIImageView alloc] init];
        _top.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"xin"]];
        [_view addSubview:_top];
        
        self.title = [[UILabel alloc] init];
//        _title.backgroundColor = [UIColor grayColor];
        [_view addSubview:_title];
        
        self.picture_num = [[UILabel alloc] init];
//        _picture_num.backgroundColor = [UIColor redColor];
        [_view addSubview:_picture_num];
        
        self.share_num = [[UILabel alloc] init];
//        _share_num.backgroundColor = [UIColor yellowColor];
        [_view addSubview:_share_num];
        
        self.top_count = [[UILabel alloc] init];
//        _top_count.backgroundColor = [UIColor blueColor];
        [_view addSubview:_top_count];
    }
    
    
    return self;
}


//颜色渐变
- (CAGradientLayer *)shadowAsInverse
{
    CAGradientLayer *newShadow = [[CAGradientLayer alloc] init];
    CGRect newShadowFrame = CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height);
    newShadow.frame = newShadowFrame;
    //横向 (0, 0)(1, 0); 纵向 (0, 0)(0, 1)
    newShadow.startPoint = CGPointMake(0, 0);
    newShadow.endPoint = CGPointMake(0, 1);
    //添加渐变的颜色组合
    newShadow.colors = [NSArray arrayWithObjects:(id)[UIColor colorWithRed:255 green:255 blue:255 alpha:0].CGColor,(id)[UIColor colorWithRed:0 green:0 blue:0 alpha:0.2].CGColor,nil];
    return newShadow;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.img.frame = CGRectMake(0, 0, self.frame.size.width, SAHeight * 250);
    
    if (self.n == 0) {
        
        [self.view.layer insertSublayer:[self shadowAsInverse] below:nil];
        self.n = 1;
    }
    
    self.title.frame = CGRectMake(SAWindth * 10, SAHeight * 200, self.frame.size.width - 20, SAHeight * 30);
    self.title.textColor = [UIColor whiteColor];
    self.picture.frame = CGRectMake(SAWindth * 10, SAHeight * 230, SAWindth * 20, SAHeight * 16);
    self.picture_num.frame = CGRectMake(SAWindth * 35, SAHeight * 230, SAWindth * 30, SAHeight * 20);
    self.picture_num.textColor = [UIColor whiteColor];
    self.share.frame = CGRectMake(SAWindth * 65, SAHeight * 230, SAWindth * 20, SAHeight * 20);
    self.share_num.frame = CGRectMake(SAWindth * 90, SAHeight * 230, SAWindth * 30, SAHeight * 20);
    self.share_num.textColor = [UIColor whiteColor];
    self.top.frame = CGRectMake(SAWindth * 120, SAHeight * 230, SAWindth * 20, SAHeight * 20);
    self.top_count.frame = CGRectMake(SAWindth * 142, SAHeight * 230, SAWindth * 40, SAHeight * 20);
    self.top_count.textColor = [UIColor whiteColor];
}


- (void)setHot:(Hot_rodModel *)hot
{
    if (_hot != hot)
    {
        _hot = hot;
    }
    
    [self.img sd_setImageWithURL:[NSURL URLWithString:hot.cover] placeholderImage:[UIImage imageNamed:@"GZZW"]];
    self.title.text = hot.name;
    self.picture_num.text = [NSString stringWithFormat:@"%@", hot.picture_num];
    self.share_num.text = [NSString stringWithFormat:@"%@", hot.share_num];
    self.top_count.text = [NSString stringWithFormat:@"%@", hot.top_count];
    
    
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
